package com.pos.app.activity.login.interactor;

import android.os.AsyncTask;

import com.pos.app.activity.login.view.ILoginFinishedListener;
import com.pos.app.comm.Constant;
import com.pos.app.model.LoginConfig;


/**
 * 登陆、注册 交互器
 * 
 * @author Administrator
 * 
 */
public class LoginInteractorImpl extends InteractorSupportImpl implements LoginInteractor
{
	// private IUserModel userModel;

	public LoginInteractorImpl()
	{
	}

	@Override
	public void login(final LoginConfig loginConfig, final ILoginFinishedListener listener)
	{
		new AsyncTask<Void, Void, Integer>()
		{

			@Override
			protected Integer doInBackground(Void... params)
			{
				int resultCode = 0;
//				try
//				{
//					XMPPConnection connection = XmppConnectionManager.getInstance().getConnection();
//					connection.connect();
//					connection.login(loginConfig.getUsername(), loginConfig.getPassword()); // 登录
//					// OfflineMsgManager.getInstance(activitySupport).dealOfflineMsg(connection);//处理离线消息
//					connection.sendPacket(new Presence(Presence.Type.available));
//					if (loginConfig.isNovisible())
//					{// 隐身登录
//						Presence presence = new Presence(Presence.Type.unavailable);
//						Collection<RosterEntry> rosters = connection.getRoster().getEntries();
//						for (RosterEntry rosterEntry : rosters)
//						{
//							presence.setTo(rosterEntry.getUser());
//							connection.sendPacket(presence);
//						}
//					}
					resultCode = Constant.LOGIN_SECCESS;
//					
//					
//				}
//				catch (Exception xee)
//				{
//					if (xee instanceof XMPPException)
//					{
//						XMPPException xe = (XMPPException) xee;
//						final XMPPError error = xe.getXMPPError();
//						int errorCode = 0;
//						if (error != null)
//						{
//							errorCode = error.getCode();
//						}
//						if (errorCode == 401)
//						{
//							resultCode = Constant.LOGIN_ERROR_ACCOUNT_PASS;
//						}
//						else if (errorCode == 403)
//						{
//							resultCode = Constant.LOGIN_ERROR_ACCOUNT_PASS;
//						}
//						else
//						{
//							resultCode = Constant.SERVER_UNAVAILABLE;
//						}
//					}
//					else
//					{
//						resultCode = Constant.LOGIN_ERROR;
//					}
//					xee.printStackTrace();
//				}
				return resultCode;
			}

			@Override
			protected void onPreExecute()
			{
				// TODO Auto-generated method stub
				super.onPreExecute();
			}

			@Override
			protected void onPostExecute(Integer result)
			{
				// TODO Auto-generated method stub
				super.onPostExecute(result);
				// 登陆返回结果
				listener.onSuccess(result);
			}
		}.execute();
	}

}
